package com.example.okhttptest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class EventActivity extends AppCompatActivity implements View.OnClickListener{

    Button haha;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event);

        //注册
        EventBus.getDefault().register(this);

        haha = findViewById(R.id.haha);
        haha.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.haha:

                startActivity(new Intent(this,CommonActivity.class));
                break;



        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getTestData(Integer num){
        if (num != null) {
            //这里拿到事件之后吐司一下
            Toast.makeText(this, "num" + num, Toast.LENGTH_SHORT).show();
        }
    }
}
